<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------
namespace app\video\behavior\create_audit_complete_after;

/**
 * 如果是长视频的话 进行剪辑
 * @package app\video\behavior\create_audit_complete_after
 * @author jason wang
 */
class produceMediaComplete{
    /**
     * 执行行为 run方法是Behavior唯一的接口
     * @access public
     * @return void
     */
    public function run($params){
    	$VideoId 	 = $params['VideoId'];

        //更新视频表状态
        $map = [];
        $map['video_id'] = $VideoId;
        $rel = model('VideoPlay') -> where($map) -> find();

        if($rel->play_type == 2 && $rel->son_play_id == 0){//表示长视频 触发 剪辑
            $main_title = $rel->main_title;
            $description = $rel -> description;
            $uid = $rel ->uid;
            $video_classid = $rel->video_classid;
            $is_original = $rel->is_original;
            $father_play_id = $rel->id;
            $clip_rel = controller('Vodlogic', 'logic')->vodClip($VideoId, $main_title, $description);
            $video_id = $clip_rel['data']['MediaId'];
            
            $video = model('VideoPlay') -> addData($uid, $video_id, $main_title, $sub_title ='', $description, $play_type=1, $is_immerse=0, $is_rotate=0, $cover_url='', $file_size='', $video_classid, $class_tage='', $is_original, $father_play_id, $play_operation_status =3);
            
            //更新 父亲的 son_play_id
            $map = [];
            $map['video_id'] = $VideoId;
            $map['son_play_id'] = 0;
            model('VideoPlay') -> where($map) -> setField('son_play_id', $video['data']);
            //复制长视频的标签 给 短视频一份
            $map = [];
            $map['play_id'] = $rel->id;
            $lable_list = model('VideoPlayLabelRelation') -> where($map) -> select();
            $data = [];
            foreach ($lable_list as $key => $value) {
                $data[] =[
                    'play_id'  => $video['data'],
                    'label_id' => $value['label_id'],
                    'create_time' => time(),
                    'update_time' => time(),
                ];
            }
            $res2 = model('VideoPlayLabelRelation') -> insertAll($data);
        }else if($rel->son_play_id > 0){//表示已经存在（自己上传的精简版）
            $map = [];
            $map['id'] = $rel->son_play_id;
            model('VideoPlay') -> where($map) -> setField('play_operation_status', 1);
        }
        
    }
}
